home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / 172aasm.zip / RBBSDV.ASM < prev    next >
Assembly Source File  |  1988-10-27  |  18KB  |  509 lines

  1. PAGE 60,132
  2. TITLE DESQview BASIC File Locking Interface Copyright 1988 by Jon Martin     
  3. ;--------------------------------------------------------------------;
  4. ;ROUTINE: LOCKDV              AUTHOR:  Jon Martin                    ;
  5. ;                                      4396 N. Prairie Willow Ct.    ;
  6. ;                                      Concord, California 94521     ;
  7. ;                                                                    ;
  8. ;DATE:  October 23, 1988      VERSION: 1.0                           ;       
  9. ;                                                                    ;
  10. ;DESCRIPTION: This subroutine enables programs written in Compiled   ;
  11. ;             BASIC to do Semaphore type resource locking when       ;
  12. ;             running in a DESQview environment.  Care was taken     ;
  13. ;             to allow the program to be fully DESQview aware.       ;
  14. ;             Programs calling this interface in a non DESQview      ;
  15. ;             environment will totally ignore the lock and unlock    ;
  16. ;             requests.  BEGINC (Begin critical) and ENDC (End       ;
  17. ;             critical) are used in a pre DESQview 2.00 environment. ;
  18. ;             API calls to Create and Test for the presence of       ;
  19. ;             mailboxes are used to implement the resource locking   ;
  20. ;             strategy when running in a DESQview 2.00 or higher     ;
  21. ;             environment.                                           ;
  22. ;                                                                    ;
  23. ;             LOCKING - Get resource name                            ;
  24. ;                       Find mailbox using resource name             ;
  25. ;                       If found then pause and loop until not found ;
  26. ;                       Create mailbox using resource name           ;
  27. ;                       return to calling program                    ;
  28. ;           UNLOCKING - Get resource name                            ;
  29. ;                       Find mailbox using resource name             ;
  30. ;                       If not found then return to calling program  ;
  31. ;                       If found then Close and Free mailbox         ;
  32. ;                       Return to calling program                    ;
  33. ;                                                                    ;
  34. ;                       BEGINC and ENDC have been wrapped around     ;
  35. ;                       those processes that were determined to be   ;
  36. ;                       necessary.                                   ;
  37. ;                                                                    ;
  38. ;FUNCTION: This routine supports calls from the IBM (MICROSOFT)      ;
  39. ;          BASIC Version 2.0 or Microsoft QuickBASIC Versions 1.0,   ;
  40. ;          2.01, 3.0, 4.00b & 4.50 compilers to the DESQview User    ;
  41. ;          Interface.  The calls are:                                ;
  42. ;                                                                    ;
  43. ;            CALL DVLOCK(resource name)                              ;
  44. ;                 a) returns if DESQview is not present              ;
  45. ;                 b) issues Begin Critical if DESQview level < 2.00  ;
  46. ;                 c) issues Lock Mailbox if DESQview level           ;
  47. ;                    >= 2.00                                         ;
  48. ;                                                                    ;
  49. ;            CALL DVUNLOCK(resource name)                            ;
  50. ;                 a) returns if DESQview is not present              ;
  51. ;                 b) issues End Critical if DESQview level <2.00     ;
  52. ;                 c) issues Unlock Mailbox if DESQview level         ;
  53. ;                    >= 2.00                                         ;
  54. ;                                                                    ;
  55. ; NOTE: "resource" must be a string and not exceed 32 characters     ;
  56. ;       Link this with your BASIC program in the following manner    ;
  57. ;                                                                    ;
  58. ;       LINK PGMNAME+LOCKDV,,,;                                      ;
  59. ;                                                                    ;
  60. ;--------------------------------------------------------------------;
  61. LOCKDV   SEGMENT BYTE PUBLIC 'CODE'
  62.  
  63.          ASSUME  CS:LOCKDV,DS:LOCKDV,ES:LOCKDV
  64.          ORG     0
  65. .xlist
  66. .SALL
  67. ;  DESQview API interfaces
  68.  
  69. ;***************************************************************
  70. ;
  71. ;  Function numbers (AX values) for the @CALL interface
  72. ;
  73. ;***************************************************************
  74.  
  75. DVC_PAUSE    EQU    1000H
  76. DVC_PRINTC    EQU    1003H
  77. DVC_GETBIT    EQU    1013H
  78. DVC_FREEBIT    EQU    1014H
  79. DVC_SETBIT    EQU    1015H
  80. DVC_ISOBJ    EQU    1016H
  81. DVC_LOCATE    EQU    1018H
  82. DVC_SOUND    EQU    1019H
  83. DVC_OSTACK    EQU    101AH
  84. DVC_BEGINC    EQU    101BH
  85. DVC_ENDC    EQU    101CH
  86. DVC_STOP    EQU    101DH
  87. DVC_START    EQU    101EH
  88. DVC_DISPEROR    EQU    101FH
  89. DVC_PGMINT    EQU    1021H
  90. DVC_POSWIN    EQU    1023H
  91. DVC_GETBUF    EQU    1024H
  92. DVC_USTACK    EQU    1025H
  93. DVC_POSTTASK    EQU    102BH
  94. DVC_NEWPROC    EQU    102CH
  95. DVC_KMOUSE    EQU    102DH
  96.  
  97. DVC_APPNUM    EQU    1107H
  98. DVC_DBGPOKE    EQU    110AH
  99. DVC_APILEVEL    EQU    110BH
  100. DVC_GETMEM    EQU    110CH
  101. DVC_PUTMEM    EQU    110DH
  102. DVC_FINDMAIL    EQU    110EH
  103. DVC_PUSHKEY    EQU    1110H
  104. DVC_JUSTIFY    EQU    1111H
  105. DVC_CSTYLE    EQU    1112H
  106.  
  107. DVC_DVPRESENT    EQU    0FFFFH
  108. DVC_SHADOW    EQU    0FFFEH
  109. DVC_UPDATE    EQU    0FFFDH
  110.  
  111. ;***************************************************************
  112. ;
  113. ;  Message numbers (BH values) for the @SEND interface
  114. ;
  115. ;***************************************************************
  116.  
  117. DVM_HANDLE    EQU    00H
  118. DVM_NEW        EQU    01H
  119. DVM_FREE    EQU    02H
  120. DVM_ADDR    EQU    03H
  121. DVM_DIR        EQU    03H
  122. DVM_READ    EQU    04H
  123. DVM_APPLY    EQU    04H
  124. DVM_WRITE    EQU    05H
  125. DVM_SIZEOF    EQU    08H
  126. DVM_LEN        EQU    09H
  127. DVM_ADDTO    EQU    0AH
  128. DVM_SUBFROM    EQU    0BH
  129. DVM_OPEN    EQU    0CH
  130. DVM_CLOSE    EQU    0DH
  131. DVM_ERASE    EQU    0EH
  132. DVM_STATUS    EQU    0FH
  133. DVM_EOF        EQU    10H
  134. DVM_AT        EQU    11H
  135. DVM_SETSCALE    EQU    11H
  136. DVM_SETNAME    EQU    11H
  137. DVM_READN    EQU    12H
  138. DVM_GETSCALE    EQU    12H
  139. DVM_REDRAW    EQU    13H
  140. DVM_SETESC    EQU    14H
  141. DVM_LOCK    EQU    14H
  142.  
  143. ;***************************************************************
  144. ;
  145. ;  Alias numbers (BL values) for the @SEND interface
  146. ;
  147. ;***************************************************************
  148.  
  149. DVA_TOS        EQU    00H
  150. DVA_ME        EQU    01H
  151. DVA_MAILTOS    EQU    02H
  152. DVA_MAILME    EQU    03H
  153. DVA_KEYTOS    EQU    04H
  154. DVA_KEYME    EQU    05H
  155. DVA_OBJQTOS    EQU    06H
  156. DVA_OBJQME    EQU    07H
  157. DVA_WINDOW    EQU    08H
  158. DVA_MAILBOX    EQU    09H
  159. DVA_KEYBOARD    EQU    0AH
  160. DVA_TIMER    EQU    0BH
  161. DVA_POINTER    EQU    0FH
  162. DVA_PANEL    EQU    10H
  163.  
  164.  
  165. ;***************************************************************
  166. ;
  167. ;  @SEND interface macro - bombs AH and BX
  168. ;
  169. ;***************************************************************
  170.  
  171. @SEND        macro    message,object
  172.         ifdef DVA_&object
  173.           MOV    BX,DVM_&message*256+DVA_&object
  174.             MOV    AH,12H
  175.           INT    15H
  176.         else        
  177.           @PUSH    &object
  178.           @SEND    &message,TOS
  179.         endif
  180.         endm
  181.  
  182. ;***************************************************************
  183. ;
  184. ;  @CALL interface macro - bombs AX
  185. ;
  186. ;***************************************************************
  187.  
  188. @CALL        macro    func
  189.             local    L1
  190.         ifndef DVC_&func
  191.           MOV    AX,&func
  192.           INT    15H
  193.         else
  194.         if (DVC_&func eq DVC_APILEVEL)
  195.           CMP    BX,200H        ; is 2.00 sufficient ?
  196.           JB    L1        ; jump if so
  197.           MOV    AX,DVC_APILEVEL    ; issue the call
  198.           INT    15H
  199.           CMP    AX,2        ; early version 2.00 ?
  200.           JNE    L1        ; jump if not
  201.           XCHG    BH,BL        ; reverse bytes
  202.           MOV    AX,DVC_APILEVEL    ; reissue call
  203.           INT    15H
  204.           XCHG    BH,BL        ; correct byte order
  205. L1:
  206.         else
  207.         if (DVC_&func eq DVC_DVPRESENT)
  208.           PUSH    BX        ; save registers
  209.           PUSH    CX
  210.           PUSH    DX
  211.           MOV    AX,2B01H    ; DOS Set Date function
  212.           XOR    BX,BX        ; in case outside DESQview
  213.           MOV    CX,'DE'        ; invalid date value
  214.           MOV    DX,'SQ'
  215.           INT    21H
  216.           MOV    AX,BX        ; version # to AX
  217.           CMP    AX,2        ; early DV 2.00 ?
  218.           JNE    L1        ; jump if not
  219.           XCHG    AH,AL        ; swap bytes if so
  220. L1:          POP    DX        ; restore registers
  221.           POP    CX
  222.           POP    BX
  223.         else
  224.         if (DVC_&func eq DVC_SHADOW)
  225.           MOV    AH,0FEH
  226.           INT    10H
  227.         else 
  228.         if (DVC_&func eq DVC_UPDATE)
  229.           MOV    AH,0FFH
  230.           INT    10H
  231.         else 
  232.           MOV    AX,DVC_&func
  233.           INT    15H
  234.         endif
  235.         endif
  236.         endif
  237.         endif
  238.         endif
  239.         endm
  240.  
  241.  
  242. ;***************************************************************
  243. ;
  244. ;  @PUSH and supporting macros - pushes 32-bit values on the stack
  245. ;
  246. ;***************************************************************
  247.  
  248. @PUSH_ESDI    macro
  249.         PUSH    ES
  250.         PUSH    DI
  251.         endm
  252.  
  253. @PUSH_DSSI    macro
  254.         PUSH    DS
  255.         PUSH    SI
  256.         endm
  257.  
  258. @PUSH_BXAX    macro
  259.         PUSH    BX
  260.         PUSH    AX
  261.         endm
  262.  
  263. @PUSH_DXCX    macro
  264.         PUSH    DX
  265.         PUSH    CX
  266.         endm
  267.  
  268. @PUSH_ESSI    macro
  269.         PUSH    ES
  270.         PUSH    SI
  271.         endm
  272.  
  273. @PUSH_DSDI    macro
  274.         PUSH    DS
  275.         PUSH    DI
  276.         endm
  277.  
  278. @PUSH        macro    parm
  279.         ifdef @PUSH_&parm
  280.           @PUSH_&parm
  281.         else          
  282.           PUSH    WORD PTR &parm+2
  283.           PUSH    WORD PTR &parm
  284.         endif
  285.         endm
  286.  
  287.  
  288. ;***************************************************************
  289. ;
  290. ;  @POP and supporting macros - pops 32-bit values from the stack
  291. ;
  292. ;***************************************************************
  293.  
  294. @POP_ESDI    macro
  295.         POP    DI
  296.         POP    ES
  297.         endm
  298.  
  299. @POP_DSSI    macro
  300.         POP    SI
  301.         POP    DS
  302.         endm
  303.  
  304. @POP_BXAX    macro
  305.         POP    AX
  306.         POP    BX
  307.         endm
  308.  
  309. @POP_DXCX    macro
  310.         POP    CX
  311.         POP    DX
  312.         endm
  313.  
  314. @POP_ESSI    macro
  315.         POP    SI
  316.         POP    ES
  317.         endm
  318.  
  319. @POP_DSDI    macro
  320.         POP    DI
  321.         POP    DS
  322.         endm
  323.  
  324. @POP        macro    parm
  325.         ifdef @POP_&parm
  326.           @POP_&parm
  327.         else          
  328.           POP    WORD PTR &parm
  329.           POP    WORD PTR &parm+2
  330.         endif
  331.         endm
  332.  
  333.  
  334. ;***************************************************************
  335. ;
  336. ;  @MOV and supporting macros - moves 32-bit values to/from memory
  337. ;
  338. ;***************************************************************
  339.  
  340. @DV_LOAD    macro    seg,off,arg
  341.         MOV    &seg,WORD PTR &arg+2
  342.         MOV    &off,WORD PTR &arg
  343.         endm
  344.  
  345. @DV_STORE    macro    seg,off,arg
  346.         MOV    WORD PTR &arg+2,&seg
  347.         MOV    WORD PTR &arg,&off
  348.         endm
  349.  
  350. @MOV_ESDI    macro    mac,arg
  351.         &mac    ES,DI,&arg
  352.         endm
  353.  
  354. @MOV_DSSI    macro    mac,arg
  355.         &mac    DS,SI,&arg
  356.         endm
  357.  
  358. @MOV_BXAX    macro    mac,arg
  359.         &mac    BX,AX,&arg
  360.         endm
  361.  
  362. @MOV_DXCX    macro    mac,arg
  363.         &mac    DX,CX,&arg
  364.         endm
  365.  
  366. @MOV_ESSI    macro    mac,arg
  367.         &mac    ES,SI,&arg
  368.         endm
  369.  
  370. @MOV_DSDI    macro    mac,arg
  371.         &mac    DS,DI,&arg
  372.         endm
  373.  
  374. @MOV        macro    dest,src
  375.         ifdef @MOV_&dest
  376.           @MOV_&dest    @DV_LOAD,&src
  377.         else
  378.           @MOV_&src    @DV_STORE,&dest
  379.         endif
  380.         endm
  381.  
  382.  
  383. ;***************************************************************
  384. ;
  385. ;  @CMP macro - compares BX:AX to DWORD in memory
  386. ;
  387. ;***************************************************************
  388.  
  389. @CMP        macro    parm
  390.         local    L1
  391.         CMP    AX,WORD PTR &parm
  392.         JNE    L1
  393.         CMP    BX,WORD PTR &parm+2
  394. L1:
  395.         endm
  396. .list
  397. CX_HOLD          DW      0
  398. SEMAPHORE        DD      0
  399. RESOURCE         DB      '                                '
  400.  
  401. DVLOCK   PROC    FAR
  402.          PUBLIC  DVLOCK 
  403.          PUSH    BP                              ;save base pointer
  404.          MOV     BP,SP                           ;establish new base
  405.          PUSH    DS                              ;save BASIC data segment
  406.          PUSH    ES                              ;save BASIC extra segment
  407.          MOV     BX,[BP+6]                       ;get string descriptor
  408.          MOV     DX,[BX+2]                       ;get address of string
  409.          MOV     CX,[BX]                         ;get length of string
  410.          MOV     CS:CX_HOLD,CX                   ;save length of string
  411.          PUSH    CS                              ;setup for ES
  412.          POP     ES                              ;ES now points to us
  413.          MOV     SI,DX                           ;offset of BASIC'S string
  414.          LEA     DI,CS:RESOURCE                  ;point to resource name
  415.          CLD                                     ;start from bottom
  416.          REP     MOVSB                           ;copy string to resource name
  417.          @CALL   DVPRESENT                       ;test for DESQview
  418.          TEST    AX,AX                           ;well is it there?
  419.          JZ      LK_EXIT                         ;zero means no
  420.          MOV     BX,200H                         ;set API level required
  421.          CMP     AX,BX                           ;is required level supported?
  422.          JNB     APILKSEM                        ;not below means ok!
  423.          @CALL   BEGINC                          ;start critical
  424. LK_EXIT:
  425.          JMP     DVLOCK_EXIT                     ;exit lock resource
  426. APILKSEM:
  427.          @CALL   APILEVEL                        ;set API level
  428. LOOP_SEMA:
  429.          @CALL   BEGINC                          ;start critical
  430.          LEA     DI,CS:RESOURCE                  ;point to resource mailbox nm
  431.          PUSH    CS                              ;setup for ES
  432.          POP     ES                              ;ES now points to us
  433.          MOV     CX,CS:CX_HOLD                   ;setup resource name len
  434.          XOR     DX,DX                           ;clear high register
  435.          @CALL   FINDMAIL                        ;find the resource mailbox
  436.          TEST    BX,BX                           ;did we find it?
  437.          JZ      MAKE_SEMA                       ;zero means nope!
  438.          @CALL   ENDC                            ;end critical
  439.          @CALL   PAUSE                           ;let's wait for awhile
  440.          JMP     LOOP_SEMA                       ;let's go try again
  441. MAKE_SEMA:
  442.          @SEND   NEW,MAILBOX                     ;create resource mailbox
  443.          @POP    CS:SEMAPHORE                    ;save semaphore
  444.          LEA     DI,CS:RESOURCE                  ;point to resource mailbox nm
  445.          PUSH    CS                              ;setup for ES
  446.          POP     ES                              ;ES now points to us
  447.          @PUSH_ESDI                              ;put address on stack
  448.          MOV     CX,CS:CX_HOLD                   ;setup resource name len
  449.          XOR     DX,DX                           ;clear high register
  450.          @PUSH_DXCX                              ;put length on stack
  451.          @SEND   SETNAME,CS:SEMAPHORE            ;let's give it a name
  452.          @CALL   ENDC                            ;end critical
  453. DVLOCK_EXIT:
  454.          POP     ES                              ;restore BASIC extra segment
  455.          POP     DS                              ;restore BASIC data segment
  456.          POP     BP                              ;restore BASIC base pointer
  457.          RET     2                               ;return to BASIC
  458. DVLOCK   ENDP
  459.  
  460. DVUNLOCK PROC    FAR
  461.          PUBLIC  DVUNLOCK
  462.          PUSH    BP                              ;save base pointer
  463.          MOV     BP,SP                           ;establish new base
  464.          PUSH    DS                              ;save BASIC data segment
  465.          PUSH    ES                              ;save BASIC extra segment
  466.          MOV     BX,[BP+6]                       ;get string descriptor
  467.          MOV     DX,[BX+2]                       ;get address of string
  468.          MOV     CX,[BX]                         ;get length of string
  469.          MOV     CS:CX_HOLD,CX                   ;save length of string
  470.          PUSH    CS                              ;setup for ES
  471.          POP     ES                              ;ES now points to us
  472.          MOV     SI,DX                           ;offset of BASIC'S string
  473.          LEA     DI,CS:RESOURCE                  ;point to resource name
  474.          CLD                                     ;start from bottom
  475.          REP     MOVSB                           ;copy string to resource name
  476.          @CALL   DVPRESENT                       ;test for DESQview
  477.          TEST    AX,AX                           ;well is it there?
  478.          JZ      UNLKSEMA_EXIT                   ;zero means no
  479.          MOV     BX,200H                         ;set API level required
  480.          CMP     AX,BX                           ;is required level supported?
  481.          JNB     APIULSEM                        ;not below means ok!
  482.          @CALL   ENDC                            ;end critical
  483. UNLKSEMA_EXIT:
  484.          JMP     DVUNLOCK_EXIT                   ;exit unlock resource
  485. APIULSEM:
  486.          @CALL   APILEVEL
  487.          LEA     DI,CS:RESOURCE                  ;point to resource mailbox nm
  488.          PUSH    CS                              ;setup for ES
  489.          POP     ES                              ;ES now points to us
  490.          MOV     CX,CS:CX_HOLD                   ;setup resource name len
  491.          XOR     DX,DX                           ;clear high register
  492.          @CALL   FINDMAIL                        ;find resource mailbox
  493.          TEST    BX,BX                           ;did we find it?
  494.          JZ      DVUNLOCK_EXIT                   ;zero means nope!
  495.          @MOV    CS:SEMAPHORE,DSSI               ;found so save semaphore
  496.          @CALL   BEGINC                          ;begin critical
  497.          @SEND   CLOSE,CS:SEMAPHORE              ;unlock resource mailbox
  498.          @SEND   FREE,CS:SEMAPHORE               ;release resource mailbox
  499.          @CALL   ENDC                            ;end critical
  500. DVUNLOCK_EXIT:
  501.          POP     ES                              ;restore BASIC extra segment
  502.          POP     DS                              ;restore BASIC data segment
  503.          POP     BP                              ;restore BASIC base pointer
  504.          RET     2                               ;return to BASIC
  505. DVUNLOCK ENDP
  506.  
  507. LOCKDV   ENDS
  508.          END
  509.